﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WF.Common;
using Com.DAO;

namespace WF.Web.Components.WorkSpace
{
    public partial class CardTimeList : BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.DataManager.Close();
            this.DataManager.Open(System.Configuration.ConfigurationManager.AppSettings.Get("KQConnectionString"));
            this.dgCardTimesList.DataManager = DataManager;

            if (!IsPostBack)
            {
                this.txtStartDate.Text = DateTime.Now.ToString("yyyy-MM-01");
                this.txtEndDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
                this.txtUser.Text = this.LogonUser.UserID.ToLower().Trim().Replace("centaline\\", "");
                this.BingList();
            }            
        }

        private void BingList()
        {
            try
            {
                string strFilter = "";
                if (this.txtStartDate.Text != "")
                {
                    strFilter += String.Format(@" And mymd >='{0}'", this.txtStartDate.Text.Trim());
                }
                if (this.txtEndDate.Text != "")
                {
                    strFilter += String.Format(@" And mymd <='{0}'", this.txtEndDate.Text.Trim());
                }
                if (this.txtUser.Text != "")
                {
                    strFilter += String.Format(@" And (DomainAccount = '{0}' Or UserName = '{0}')", this.txtUser.Text.Trim());
                }

                strFilter += " Order By mymd Desc ";

                this.dgCardTimesList.DataSourceTable = "ViewCardTimeList";
                this.dgCardTimesList.DataSourceFilter = strFilter;
                this.dgCardTimesList.BindData();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }       

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.BingList();
        }
    }
}